﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Catering.Catering_Page.JieGouJianKong
{
    public partial class GridViewShiwuYingyang : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["foodId"] != null && !string.IsNullOrEmpty(Request.QueryString["foodId"]) && Request.QueryString["level"] != null && !string.IsNullOrEmpty(Request.QueryString["level"]))
            {
                string foodId = "";
                int level = 0;
                if (Request.QueryString["foodId"] != null && !string.IsNullOrEmpty(Request.QueryString["foodId"]) && Request.QueryString["level"] != null && !string.IsNullOrEmpty(Request.QueryString["level"]))
                {
                    foodId = Request.QueryString["foodId"];
                    level = Int32.Parse(Request.QueryString["level"]);
                }
                else if (Session["foodid"] != null && Session["level"] != null)
                {
                    foodId = Session["foodid"].ToString();
                    level =Int32.Parse(Session["level"].ToString());
                }
                if (!IsPostBack)
                {
                    Session["foodid"] = foodId;
                    Session["level"] = level.ToString();
                    Catering_Rules.T_RawMaterial rawMaterialRule = new Catering_Rules.T_RawMaterial();
                    DataTable dt = rawMaterialRule.GetRawMaterialById(Int32.Parse(foodId), level);
                    if (dt.Rows.Count == 0)
                    {
                        Catering_Rules.T_RawMaterial tempRules = new Catering_Rules.T_RawMaterial();
                        Catering_Model.E_RawMaterial model = tempRules.GetModel(Int32.Parse(foodId));
                        DataRow tempDR = dt.NewRow();
                        tempDR[0] = foodId;
                        tempDR[1] = model.RAWIDS;
                        tempDR[2] = model.RAWName;
                        for (int i = 3; i < dt.Columns.Count; i++)
                        {
                            tempDR[i] = "0.00";
                        }
                        dt.Rows.Add(tempDR);
                    }
                    NoticeRept.DataSource = dt;
                    NoticeRept.DataBind();
                }
            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }
    }
}